package com.mz.ozy.adapter;

import android.widget.ImageView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.mz.ozy.R;
import com.mz.ozy.bean.OrderLogisticsInfoBean;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import androidx.annotation.Nullable;

/**
 * Created by Administrator on 2018/11/23.
 */

public class LogisticsInfoAdapter extends BaseQuickAdapter<OrderLogisticsInfoBean.logisticsBean.logisticsDataList, BaseViewHolder> {


    private final SimpleDateFormat mFormat;
    private final SimpleDateFormat mFormatDate;
    private final SimpleDateFormat mFormatTime;

    public LogisticsInfoAdapter(@Nullable List<OrderLogisticsInfoBean.logisticsBean.logisticsDataList> data) {
        super(R.layout.view_item_logistics_info, data);
        mFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

        mFormatDate = new SimpleDateFormat("MM-dd");
        mFormatTime = new SimpleDateFormat("HH:mm");
    }

    @Override
    protected void convert(BaseViewHolder helper, OrderLogisticsInfoBean.logisticsBean.logisticsDataList item) {
        ImageView ivDot = helper.getView(R.id.iv_dot);

        Date date = null;
        try {
            date = mFormat.parse(item.getTime());
        } catch (Exception e) {

        }

        if (helper.getAdapterPosition() == 0) {
            ivDot.setBackgroundResource(R.mipmap.wu_pre);
        } else {
            ivDot.setBackgroundResource(R.mipmap.wu_normal);
        }

        if (date == null) {
            helper.setText(R.id.tv_date, "--")
                    .setText(R.id.tv_time, "--")
                    .setText(R.id.tv_context, item.getContext())
                    .setText(R.id.tv_describe, item.getStatus());
        } else {
            helper.setText(R.id.tv_date, mFormatDate.format(date))
                    .setText(R.id.tv_time, mFormatTime.format(date))
                    .setText(R.id.tv_context, item.getContext())
                    .setText(R.id.tv_describe, item.getStatus());
        }
    }
}
